package cn.sz.hy.logic.strategy.vo;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import jxl.Sheet;

public class TableVo
{
    private List<Integer> keyArray = new ArrayList<Integer>();

    private Sheet sheet;

    private List<SheetItem> columns = new ArrayList<SheetItem>();

    private String sheetName;

    public int row;

    public TableVo(List<SheetItem> columns, Sheet sheet, String sheetName) {
        super();
        setColumns(columns);
        this.sheetName = sheetName;
        this.sheet = sheet;
    }

    public Integer[] getKeyArray()
    {
        Integer[] keys = new Integer[keyArray.size()];
        keyArray.toArray(keys);
        return keys;
    }

    public List<SheetItem> getColumns()
    {
        return columns;
    }

    public void setColumns(List<SheetItem> columns)
    {
        if (columns == null)
        {
            return;
        }
        this.columns.clear();
        this.columns.addAll(columns);
        Iterator<SheetItem> itr = this.columns.iterator();
        while (itr.hasNext())
        {
            itr.next().setPatent(this);
        }
    }

    public String getSheetName()
    {
        return sheetName;
    }

    public void setSheetName(String sheetName)
    {
        this.sheetName = sheetName;
    }

    public Sheet getSheet()
    {
        return sheet;
    }

    public void setSheet(Sheet sheet)
    {
        this.sheet = sheet;
    }

    public void setKeyArray(Integer[] keyArray)
    {
        this.keyArray.clear();
        for (Integer key : keyArray)
        {
            this.keyArray.add(key);
        }
    }

    public void insertItem(SheetItem item, int index)
    {
        columns.add(index, item);
    }

    public void addKey(Integer column)
    {
        if (!keyArray.contains(column))
        {
            keyArray.add(column);
        }
    }
}
